package com.qyer.commons.kafka;

import org.apache.kafka.common.errors.SerializationException;
import org.apache.kafka.common.serialization.Serializer;

import java.util.Map;

/**
 * User: Z J Wu Date: 2016/07/22 Time: 14:33 Package: com.qyer.commons.kafka
 */
public class SelfSerializableRecordSerializer<T extends SelfSerializableRecord> implements
  Serializer<T> {

  @Override
  public void configure(Map<String, ?> configs, boolean isKey) {

  }

  @Override
  public byte[] serialize(String topic, T data) {
    if (data == null) {
      return null;
    }
    try {
      return data.toBytes();
    } catch (Exception e) {
      throw new SerializationException("Cannot serialize data to bytes.", e);
    }
  }

  @Override
  public void close() {

  }
}
